/*
 * @Author: linjituan linjituan@revolution.com
 * @Date: 2024-11-23 16:18:51
 * @LastEditors: linjituan linjituan@revolution.com
 * @LastEditTime: 2024-11-26 20:44:23
 * @FilePath: \hm-twx-admin\src\utils\metaidv2api.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// showapi相关接口
import { get, post } from './http/axios'

export const getMetaidManHost = async () => {
	let network = 'mainet'
	if ((window as any).metaidwallet) {
		network = (await (window as any).metaidwallet.getNetwork()).network
	}
	if ('testnet' == network) {
		return 'https://man-test.metaid.io'
	}
	return 'https://man.metaid.io'
}

export const getAllPinByPath = async (page, limit, path, address) => {
	const metaidManHost = await getMetaidManHost()
	let url = `${metaidManHost}/api/getAllPinByPath?page=${page}&limit=${limit}&path=${path}`
	if (address) {
		url = `${metaidManHost}/api/address/pin/list/owner/${address}?cnt=true&cursor=${page - 1
			}&size=${limit}&path=${path}`
	}

	return get(url, undefined, undefined)
}

export const getAllPinByPathAndMetaId = async (p) => {
	const metaidManHost = await getMetaidManHost()
	let url = `${metaidManHost}/api/getAllPinByPathAndMetaId`

	return post(url, p, undefined)
}

export const queryOneBuzz = async (id) => {
	const metaidManHost = await getMetaidManHost()
	const url = `${metaidManHost}/api/pin/${id}`
	return get(url, undefined, undefined)
}

export const getMetaidByAddress = async (address) => {
	const metaidManHost = await getMetaidManHost()
	const url = `${metaidManHost}/api/info/address/${address}`
	return get(url, undefined, undefined)
}

export const getFollowingList = async (metaid, cursor, size) => {
	const metaidManHost = await getMetaidManHost()
	const url = `${metaidManHost}/api/metaid/followingList/${metaid}?cursor=${cursor}&size=${size}&followDetail=false`
	return get(url, undefined, undefined)
}

export const getFollowerList = async (metaid, cursor, size) => {
	const metaidManHost = await getMetaidManHost()
	const url = `${metaidManHost}/api/metaid/followerList/${metaid}?cursor=${cursor}&size=${size}&followDetail=false`
	return get(url, undefined, undefined)
}

export const getFollowRecord = async (metaid, followerMetaId) => {
	const metaidManHost = await getMetaidManHost()
	const url = `${metaidManHost}/api/follow/record?metaId=${metaid}&followerMetaId=${followerMetaId}`
	return get(url, undefined, undefined)
}

export const generalQuery = async (p) => {
	const metaidManHost = await getMetaidManHost()
	const url = `${metaidManHost}/api/generalQuery`
	return post(url, p, undefined)
}

export async function notify({ txHex }) {
	const url = 'https://api.metaid.io/metaid-base/v1/meta/upload/raw'

	await post(url, {
		raw: txHex,
		type: 1
	}, undefined)
}
